package com.itqian.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itqian.system.entity.Announcement;
import com.itqian.system.form.AnnouncementForm;
import com.itqian.system.mapper.AnnouncementMapper;
import com.itqian.system.service.AnnouncementService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 网站公告表 服务实现类
 * </p>
 *
 * @author shishuqian
 * @since 2022-03-21
 */
@Service
public class AnnouncementServiceImpl extends ServiceImpl<AnnouncementMapper, Announcement> implements AnnouncementService {

    @Autowired
    private AnnouncementMapper announcementMapper;

    @Override
    public boolean add(AnnouncementForm form) {
        Announcement announcement = new Announcement();
        BeanUtils.copyProperties(form,announcement);
        int insert = announcementMapper.insert(announcement);
        return insert == 1;
    }

    @Override
    public Page<Announcement> list(Integer page, Integer size) {
        Page<Announcement> announcementPage = new Page<>(page, size);
        QueryWrapper<Announcement> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("update_time");
        Page<Announcement> selectPage = announcementMapper.selectPage(announcementPage, wrapper);
        return selectPage;
    }
}
